#include "mainwindow.h"
#include "qmediaplaylist.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include<QtMultimedia/QMediaPlayer>
#include<QtMultimedia/QMediaPlaylist>
#include<QFileDialog>
#include<QDir>
#include<QPoint>
#include<QNetworkAccessManager>
#include<QVariant>
#include<QByteArray>
#include<QJsonParseError>
#include<QJsonDocument>
#include<QJsonObject>
#include<QJsonArray>
#include<QUrl>
#include<QPixmap>
#include<QMapIterator>
#include <QTableWidget>
#include <QTableWidgetItem>
#include<QRegExp>
#include <qdebug.h>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include"songinfo.h"
#include"lenon.h"
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    init();     //初始化相关函数
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::init()
{
    PlayerList = new QMediaPlaylist;    //实例化播放器和播放列表
    Player = new QMediaPlayer;
    PlayerList->setPlaybackMode(QMediaPlaylist::Sequential); //播放模式 循环，单曲等等
    Player->setVolume(50);
    Player->setPlaylist(PlayerList); //将播放列表加载到播放器
    Player->setNotifyInterval(500); //设置positionChanged信号发送频率，毫秒级别

    //信号绑定
    connect(PlayerList,SIGNAL(currentIndexChanged(int)),this,SLOT(onPlaylistChanged(int)));
    connect(Player,SIGNAL(positionChanged(qint64)),this,SLOT(onPositionChanged(qint64)));
    connect(Player,SIGNAL(durationChanged(qint64)),this,SLOT(onDurationChanged(qint64)));

    //构造函数中进行信号和槽的链接
    //connect 有不同的写法，replyFinished也就是replyFinished()。
    network_manager = new QNetworkAccessManager();
    network_request = new QNetworkRequest();
    network_manager2 = new QNetworkAccessManager();
    network_request2 = new QNetworkRequest();
    network_manager3 = new QNetworkAccessManager();
    network_request3 = new QNetworkRequest();
    connect(network_manager, &QNetworkAccessManager::finished, this, &MainWindow::replyFinished);
    connect(network_manager2, &QNetworkAccessManager::finished, this, &MainWindow::replyFinished2);
    connect(network_manager3, &QNetworkAccessManager::finished,this, &MainWindow::replyFinished3);
    myMapper = new QSignalMapper(this);
    QPushButton * button[8]={ui->pushButton_18,ui->pushButton_19,ui->pushButton_20,ui->pushButton_22,ui->pushButton_23,
                              ui->pushButton_24,ui->pushButton_25,ui->pushButton_26};
    for(int i = 0,j = 2;i<8;i++)
    {
        connect(button[i], SIGNAL(clicked(bool)), myMapper, SLOT(map()));
        myMapper->setMapping(button[i], i);
        j++;
    }
    connect(myMapper, SIGNAL(mapped(int)), this, SLOT(setPushButton(int)));

    this->setWindowFlags(Qt::FramelessWindowHint);  //去掉窗口标题栏


    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);//搜索表格整行选中的方式


    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    //搜索表格每列宽度
    ui->tableWidget->setColumnWidth(0,240);
    ui->tableWidget->setColumnWidth(1,190);
    ui->tableWidget->setColumnWidth(2,210);
    ui->tableWidget->setColumnWidth(3,140);
    ui->tableWidget->setColumnWidth(4,100);


    //搜索表格去除选中虚线框
    ui->tableWidget->setFocusPolicy(Qt::NoFocus);

    //搜索表格不显示网格线
    ui->tableWidget->setShowGrid(false);

    connect(&timer, &QTimer::timeout,this, &MainWindow::onAutoPlay);
    timer.start(2000);
}

void MainWindow::on_pushButton_12_clicked()//播放
{
    if(m_IsPause==true)//false 为播放
    {
        ui->pushButton_12->setStyleSheet("border-image: url(:/small photo/images/btn_paly_h.png)");
        m_IsPause = false;
        Player->pause();
        return;
    }
    m_IsPause = true;
    ui->pushButton_12->setStyleSheet("border-image: url(:/small photo/images/purse.png);");
    Player->play();
}


void MainWindow::on_pushButton_13_clicked()  //下一曲
{
    qDebug()<<"m_Amount "<<PlayerList->mediaCount();
    m_Amount = PlayerList->mediaCount();//总数
    if(m_Value == m_Amount)
    {
        m_Value =0;
        PlayerList->setCurrentIndex(m_Value);
        if(m_IsPause==true)
        {
            Player->play();
        }
        return;
    }
    PlayerList->setCurrentIndex(++m_Value);
    if(m_IsPause==true)
    {
        Player->play();
    }

}

void MainWindow::on_pushButton_11_clicked()  //上一曲
{
    m_Amount = PlayerList->mediaCount();
    if(m_Value == 0)
    {
        m_Value=m_Amount;
        PlayerList->setCurrentIndex(m_Value);
        if(m_IsPause==true)
        {
            Player->play();
        }
        return;
    }
    PlayerList->setCurrentIndex(--m_Value);
    if(m_IsPause==true)
    {
        Player->play();
    }
}

void MainWindow::on_pushButton_15_clicked()   //播放顺序
{

    if(m_IsMode == 0)//单曲
    {
        ui->pushButton_15->setStyleSheet("border-image: url(:/small photo/9f3e6b817aef30c372fabf0473a8413.png);");
        m_IsMode++;
        return;
    }
    if(m_IsMode == 1)//循环
    {
        ui->pushButton_15->setStyleSheet("border-image: url(:/small photo/6e69ae525a44274208d0557ba191b1e.png);");
        m_IsMode++;
        return;
    }
    if(m_IsMode == 2)//单曲循环
    {
        ui->pushButton_15->setStyleSheet("border-image: url(:/small photo/077219bdce309ac9cc167a46800fe19.png);");
        m_IsMode++;
        return;
    }
    if(m_IsMode == 3)//随机
    {
        ui->pushButton_15->setStyleSheet("border-image: url(:/small photo/53585307994e0b98ba61bd8151f9714.png);");
        m_IsMode =0;
        return;
    }

}
void MainWindow::on_pushButton_14_clicked()
{
    QString curPash =QDir::currentPath();
    QString dlgTitle="选择音频文件";
    QString filter="音频文件(*.mp3 *.wav *.wma)mp3文件(*.mp3);;wav文件(*.wav);;wma文件(*.wma);;所有文件(*.*)";
    QStringList fileList = QFileDialog::getOpenFileNames(this,dlgTitle,curPash,filter);
    if(fileList.count()<1)
        return;
    for(int i = 0;i<fileList.count();i++)
    {
        QString aFile = fileList.at(i);
        qDebug()<<aFile;
        PlayerList->addMedia(QUrl::fromLocalFile(aFile));
        QFileInfo fileInfo(aFile);
        ui->listWidget->addItem(fileInfo.fileName());
    }
    if(Player->state()!=QMediaPlayer::PlayingState)
    {
        PlayerList->setCurrentIndex(m_Value);
    }
    Player->play();
}
void MainWindow::onPlaylistChanged(int position)//显示当前播放的歌名与歌手
{
    ui->listWidget->setCurrentRow(position);
    QListWidgetItem * item = ui->listWidget->currentItem();
    if(item)
    {
        ui->label_2->setText(item->text());
        ui->label_3->setText(item->text());
    }
}

void MainWindow::onDurationChanged(qint64 duration)
{
    ui->horizontalSlider->setMaximum(duration); //设置进度条最大值 也就是歌曲时长 ms
    int secs = duration/1000; //全部秒数
    int mins = secs/60;//分
    secs = secs % 60;//秒
    durationTime = QString::asprintf("%d:%d",mins,secs);
    ui->label_5->setText(durationTime);
}
void MainWindow::onPositionChanged(qint64 position)
{
    if(ui->horizontalSlider->isSliderDown())
        return;//如果手动调整进度条，则不处理
    ui->horizontalSlider->setSliderPosition(position);
    int secs = position/1000;
    int mins = secs/60;
    secs = secs % 60;
    positionTime = QString::asprintf("%d:%d",mins,secs);
    ui->label_4->setText(positionTime);

    int pos = position/10;
    QMap<int, QString>::iterator iter = lrcMap.begin();
    while (iter != lrcMap.end())
    {
        if(pos-50<=iter.key()&& pos+50>=iter.key())
        {
            int j=0;
            if(iter != lrcMap.begin())
            {
                iter--;
                ui->label_17->setText(iter.value());
                j++;
            }
            if(iter != lrcMap.begin())
            {
                iter--;
                ui->label_16->setText(iter.value());
                j++;
            }

            if(iter != lrcMap.begin())
            {
                iter--;
                ui->label_10->setText(iter.value());
                j++;
            }
            for(;j>0;j--)
            {
                iter++;
            }
            //中间
            ui->label_18->setText(iter.value());
            iter++;
            if(iter != lrcMap.end())
            {
                ui->label_19->setText(iter.value());
            }
            else
            {
                ui->label_19->setText("");
                return;
            }
            iter++;
            if(iter != lrcMap.end())
            {
                ui->label_20->setText(iter.value());
            }
            else
            {
                ui->label_20->setText("");
                return;
            }
            iter++;
            if(iter != lrcMap.end())
            {
                ui->label_21->setText(iter.value());
            }
            else
            {
                ui->label_21->setText("");
                return;
            }
            iter++;
            if(iter != lrcMap.end())
            {
                ui->label_22->setText(iter.value());
            }
            else
            {
                ui->label_22->setText("");
                return;
            }
            iter++;
            if(iter != lrcMap.end())
            {
                ui->label_23->setText(iter.value());
            }
            else
            {
                ui->label_23->setText("");
                return;
            }
            iter++;
            if(iter != lrcMap.end())
            {
                ui->label_24->setText(iter.value());
            }
            else
            {
                ui->label_24->setText("");
                return;
            }
        }
        iter++;
    }



}


// 轮播图
void MainWindow::onAutoPlay()
{
    static int index = 0;
    if (index >= 5) {
        index = 0;
    }

    switch (index) {
    case 0:
        ui->radioButton->setChecked(true);
        ui->stackedWidget->setCurrentWidget(ui->page);
        break;
    case 1:
        ui->radioButton_2->setChecked(true);
        ui->stackedWidget->setCurrentWidget(ui->page_2);
        break;
    case 2:
        ui->radioButton_3->setChecked(true);
        ui->stackedWidget->setCurrentWidget(ui->page_3);
        break;
    case 3:
        ui->radioButton_4->setChecked(true);
        ui->stackedWidget->setCurrentWidget(ui->page_4);
        break;
    case 4:
        ui->radioButton_5->setChecked(true);
        ui->stackedWidget->setCurrentWidget(ui->page_5);
        break;
    default:
        break;
    }

    index++;
}

void MainWindow::on_pushButton_6_clicked()
{
    showMinimized();
}

void MainWindow::on_pushButton_7_clicked()
{
    close();
}

void MainWindow::on_pushButton_41_clicked()
{
    showMaximized();
}

void MainWindow::on_horizontalSlider_sliderReleased()
{
    Player->setPosition(ui->horizontalSlider->value());
}

void MainWindow::on_horizontalSlider_2_valueChanged(int value)
{
    Player->setVolume(value);
}

void MainWindow::on_pushButton_16_clicked()//音量调节，点击静音
{
    if(m_IsVolume ==true)
    {
        m_IsVolume = false;
        ui->pushButton_16->setStyleSheet("border-image: url(:/small photo/0a1966391a8ebc473f80bed007cb2f0.png);");
        Player->setVolume(ui->horizontalSlider_2->value());
        return;
    }
    m_IsVolume = true;
    ui->pushButton_16->setStyleSheet("border-image: url(:/small photo/edd96402b0359facf4673510a3ab323.png);");
    Player->setVolume(0);
}




//网络搜索歌曲的实现
//搜索按钮
void MainWindow::search(QString str,int page = 1,int pagesize=30)
{
    QString KGAPISTR1 = QString("http://mobilecdn.kugou.com/api/v3/search/song?format=json"
                                "&keyword=%1&page=%2&pagesize=%3").arg(str).arg(page).arg(pagesize);
    network_request->setUrl(QUrl(KGAPISTR1));
    network_manager->get(*network_request);
}
//槽函数
void MainWindow::replyFinished(QNetworkReply *reply)
{

    //获取响应的信息，状态码为200表示正常
    QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

    if(reply->error() == QNetworkReply::NoError)
    {
        QByteArray bytes = reply->readAll();  //获取字节
        QString result(bytes);                //转化为字符串
        JI = parseJson(result);
    }
    else
    {
        qDebug()<<"搜索信息处理错误";
    }

    IsExecute = 0;
}

QVector<SongInfo> MainWindow::parseJson(QString json)
{
    JI.clear();

    QByteArray byte_array;
    QJsonParseError json_error;
    QJsonDocument parse_doucment = QJsonDocument::fromJson(byte_array.append(json), &json_error);
    qDebug() << json;
    if (json_error.error == QJsonParseError::NoError)
    {
        if (parse_doucment.isObject())
        {
            QJsonObject rootObj = parse_doucment.object();
            if (rootObj.contains("data"))
            {
                QJsonValue valuedata = rootObj.value("data");
                if (valuedata.isObject())
                {
                    QJsonObject valuedataObject = valuedata.toObject();
                    if (valuedataObject.contains("info"))
                    {
                        QJsonValue valueArray = valuedataObject.value("info");
                        if (valueArray.isArray())
                        {
                            QJsonArray array = valueArray.toArray();
                            int size = array.size();
                            ui->tableWidget->setRowCount(size);//设置列数
                            for (int i = 0; i < size; i++)
                            {
                                QJsonValue value = array.at(i);
                                if (value.isObject())
                                {
                                    QJsonObject object = value.toObject();
                                    //收集数据
                                    SongInfo info;
                                    info.name = getcontains(object,"songname_original");
                                    info.singer = getcontains(object,"singername");
                                    info.album = getcontains(object,"album_name");
                                    info.hash = getcontains(object,"hash");
                                    info.id = getcontains(object,"album_id");
                                    info.duration = 0;
                                    if (object.contains("duration"))//时长
                                    {
                                        QJsonValue AlbumID_value = object.take("duration").toInt();
                                        info.duration = AlbumID_value.toInt();
                                    }

                                    JI.append(info);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    else
    {
        qDebug() << json_error.errorString();
    }

    for (int i = 0; i <ui->tableWidget->rowCount(); i++) {
        ui->tableWidget->removeRow(i);
    }

    for(int i =0;i<JI.size();i++)
    {
        SongInfo info = JI.at(i);
        if (info.name.isEmpty())
        {
            return JI;
        }

        int row = ui->tableWidget->rowCount()+1;
        ui->tableWidget->setRowCount(row);
        //歌曲
        QTableWidgetItem* item = new QTableWidgetItem(info.name);
        item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        ui->tableWidget->setItem(i,0,item);

        //歌手
        if (!info.singer.isEmpty()) {
            item = new QTableWidgetItem(info.singer);
        } else {
            item = new QTableWidgetItem(QStringLiteral("未知歌手"));
        }
        item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        ui->tableWidget->setItem(i,1,item);

        //专辑
        if (!info.album.isEmpty()) {
            item = new QTableWidgetItem(info.album);
        } else {
            item = new QTableWidgetItem("-");
        }
        item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        ui->tableWidget->setItem(i,2,item);

        //时长
        if (info.duration > 0) {
            QString time = QString("%1:%2").arg(info.duration/60).arg(info.duration%60);
            item = new QTableWidgetItem(time);
        } else {
             item = new QTableWidgetItem("00:00");
        }
        item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        ui->tableWidget->setItem(i,3,item);
    }

    return JI;
}
//双击音乐播放
void MainWindow::on_tableWidget_cellDoubleClicked(int row, int column)
{
    //歌曲请求
    QString KGAPISTR1 =QString("https://www.kugou.com/yy/index.php?r=play/getdata"
                                "&hash=%1&album_id=%2&_=1497972864535").arg(JI.at(row).hash).arg(JI.at(row).id);
    //QString KGAPISTR1 =QString("https://www.kugou.com/yy/index.php?r=play/getdata&hash=1112A64F5B265256186A306753951217&album_id=522097&_=1497972864535");
    network_request2->setUrl(QUrl(KGAPISTR1));
    //qDebug()<<"歌曲详细列表"<<KGAPISTR1;

    network_request2->setRawHeader("Cookie","kg_mid=233");
    network_request2->setHeader(QNetworkRequest::CookieHeader, 2333);
    network_manager2->get(*network_request2);
}


void MainWindow::replyFinished2(QNetworkReply *reply)
{
    //清空缓存
    lrcMap.clear();
    //获取响应的信息，状态码为200表示正常
    QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

    //无错误返回
    if(reply->error() == QNetworkReply::NoError)
    {
        QByteArray bytes = reply->readAll();  //获取字节
        QString result(bytes);  //转化为字符串
        parseJsonSongInfo(result);
    }
    else
    //处理错误
    {
        qDebug()<<"处理错误2";
    }
}


void MainWindow::parseJsonSongInfo(QString json)
{
    qDebug()<<"数据:"<<json;
    QByteArray byte_array;
    QJsonParseError json_error;
    QJsonDocument parse_doucment = QJsonDocument::fromJson(byte_array.append(json), &json_error);
    if(json_error.error == QJsonParseError::NoError)
    {
        if(parse_doucment.isObject())
        {
            QJsonObject rootObj = parse_doucment.object();
            if(rootObj.contains("data"))
            {
                QJsonValue valuedata = rootObj.value("data");
                if(valuedata.isObject())
                {
                    QJsonObject valuedataObject = valuedata.toObject();
                    //播放
                    QString url = getcontains(valuedataObject,"play_url");
                    PlayerList->addMedia(QUrl::fromLocalFile(url));

                    PlayerList->setCurrentIndex(PlayerList->mediaCount()-1);
                    m_IsPause = true;
//                    ui->pushButton_2->setStyleSheet("border-image: url(:/lib/1zantingtingzhi.png);");
                    Player->play();
                    //qDebug()<<"地址"<<url;
                    //歌名显示
                    music.albumid = getcontains(valuedataObject,"album_id");
                    music.songname = getcontains(valuedataObject,"song_name");
                    music.authorname = getcontains(valuedataObject,"author_name");
                    music.albumname = getcontains(valuedataObject,"album_name");
                    //music.time = getcontains(valuedataObject,"timelength").toInt();
                    if (valuedataObject.contains("timelength"))//时长
                    {
                        QJsonValue timejson = valuedataObject.take("timelength").toInt()/1000;
                        music.time = QString("%1:%2").arg(timejson.toInt()/60).arg(timejson.toInt()%60);
                        //qDebug()<<"时间"<<timestr;
                    }
                    ui->label_2->setText(music.songname);
                    ui->label_3->setText(music.authorname);
                    //QFileInfo fileInfo(name);

                    //歌词获取
                    QString lrc = getcontains(valuedataObject,"lyrics");
                    QStringList lrclist = lrc.split("\n");
                    for(int i =3;i<lrclist.size()-1;i++)
                    {
                        QString ss1 = lrclist.at(i);
                        QRegExp ipRegExp = QRegExp("\\[\\d\\d\\S\\d\\d\\S\\d\\d\\]");
                        bool match = ipRegExp.indexIn(lrclist.at(i));
                        if(match == false)
                        {
                            //时间解析格式(分*60+秒)*100+厘秒
                            int s_1 = ss1.mid(1,2).toInt();      //分
                            int s_2 = ss1.mid(4,2).toInt();      //秒
                            int s_3 = ss1.mid(7,2).toInt();      //厘秒
                            int lrctime = (s_1*60+s_2)*100+s_3;   //规定写法
                            QString lrcstr = ss1.mid(10);
                            lrcMap.insert(lrctime,lrcstr);
                        }
                    }
                    //图片显示
                    network_request3->setUrl(QUrl(getcontains(valuedataObject,"img")));
                    network_manager3->get(*network_request3);
                    //将播放记录添加到历史记录
                    //如果无，则创建数据库，如果有，则追加。
                    //建立并打开数据库
                    QSqlQuery sql_query = music.createData();//创建数据库，数据表
                    //将播放写入记录
                    //导入数据
                    QString strdb = QString("INSERT INTO music VALUES(\"%1\", \"%2\", \"%3\", \"%4\", \"%5\", \"%6\")").arg(music.albumid,music.songname,music.authorname,music.albumname,music.time,"0");
                    if(!sql_query.exec(strdb))
                    {
                        qDebug() << sql_query.lastError();
                    }
                    else
                    {
                        qDebug() << "inserted Wang!";
                    }
                    //读取数据
                    //查询数据
                    sql_query.exec("select * from music");
                    if(!sql_query.exec())
                    {
                        qDebug()<<sql_query.lastError();
                    }
                    else
                    {
                        for (int i = 0; i <ui->tableWidget->rowCount(); i++) {
                            ui->tableWidget->removeRow(i);
                        }

                        int i = 0;
                        while(sql_query.next())
                        {
                            int row = ui->tableWidget->rowCount();
                            ui->tableWidget->setRowCount(row + 1);
                            QString albumid_d =sql_query.value(0).toString();
                            QString songname_d = sql_query.value(1).toString();
                            QString singname_d = sql_query.value(2).toString();
                            QString albumname_d = sql_query.value(3).toString();
                            QString time_d = sql_query.value(4).toString();
                            //歌曲
                            qDebug()<<QString("album_id:%1    song_name:%2    sing_name:%3    album_name:%4   time:%5   playnumber:%6").arg(albumid_d,songname_d,singname_d,albumname_d,time_d,"2");
                            //歌曲
                            ui->tableWidget->setItem(i,0,new QTableWidgetItem(songname_d));
                            ui->tableWidget->item(i,0)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
                            //歌手
                            ui->tableWidget->setItem(i,1,new QTableWidgetItem(singname_d));
                            ui->tableWidget->item(i,1)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
                            //专辑
                            ui->tableWidget->setItem(i,2,new QTableWidgetItem(albumname_d));
                            ui->tableWidget->item(i,2)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
                            //时长
                            ui->tableWidget->setItem(i,3,new QTableWidgetItem(time_d));
                            ui->tableWidget->item(i,3)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
                            i++;
                        }
                    }
                }
                else
                {
                    qDebug()<<"出错";
                }
            }
        }
    }
}

void MainWindow::hideAll()
{
    QPushButton * button[8]={ui->pushButton_18,ui->pushButton_19,ui->pushButton_20,ui->pushButton_22,ui->pushButton_23,
                              ui->pushButton_24,ui->pushButton_25,ui->pushButton_26};
    for(int i = 0;i<8;i++)
    {
        button[i]->setStyleSheet("text-align:left;color: rgb(255, 255, 255);border-radius:5px;");
    }
}

void MainWindow::setPushButton(int index)
{
    //qDebug()<<"  序号："<<index+2;
    hideAll();
    ui->stackedWidget->setCurrentIndex(index+2);
    QPushButton * button[8]={ui->pushButton_18,ui->pushButton_19,ui->pushButton_20,ui->pushButton_22,ui->pushButton_23,
                              ui->pushButton_24,ui->pushButton_25,ui->pushButton_26};
    button[index]->setStyleSheet("text-align:left;color: rgb(255, 255, 255);border-radius:5px;border-width:1px;border-style:solid;border-color: rgba(232, 232, 232, 10);background-color: rgba(232, 232, 232, 100);");
}

QString MainWindow::getcontains(QJsonObject Object, QString strInfo)
{
    if (Object.contains(strInfo))
    {
        QJsonValue value = Object.take(strInfo);
        if (value.isString())
        {
            return value.toString();
        }
    }
    return "";
}






void MainWindow::replyFinished3(QNetworkReply *reply)
{
    //获取响应的信息，状态码为200表示正常
    QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    //无错误返回
    if(reply->error() == QNetworkReply::NoError)
    {

        QByteArray bytes = reply->readAll();  //获取字节
        QPixmap pixmap;
        QSize picSize(45,45);
        pixmap.loadFromData(bytes);
        //pixmap.save(".pixmap//123456.jpg");
        ui->label_25->setPixmap(pixmap.scaled(picSize));
    }
    else
    {
        //处理错误
        qDebug()<<"处理错误3";
    }
}



void MainWindow::on_pushButton_48_clicked()
{
    //清理缓存
    JI.clear();

    ui->tabWidget->setCurrentWidget(ui->tab_3);

    //得到数据，然后再进行操作
    search(ui->lineEdit->text());
    //列表显示在这里进行

}

void MainWindow::on_pushButton_10_clicked()
{    hideAll();
    if(m_IsLyricsShow == false)
    {
        //获取当前页面的索引

        ui->pushButton_17->setStyleSheet("border-radius:5px;border-image: url(:/lib/zhankai.png);background-color: rgba(225, 225, 225, 10);");

        m_IsLyricsShow = true;
    }
    else
    {
        ui->pushButton_17->setStyleSheet("border-radius:5px;border-image: url(:/lib/zedian.png);background-color: rgba(225, 225, 225, 10);");
        m_IsLyricsShow = false;
    }
}

